g# -*- coding: utf-8 -*-
'''
@author: Hugo
@file: fron_encode_teacher.py
@time: 2021/9/4 13:50
'''
import re

url = 'https://maoyan.com/films/1218188'

headers = {
    'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/92.0.4515.159 Safari/537.36',
    'Referer': 'https://maoyan.com/',
    'cookie': "__mta=244242106.1628254145571.1630245829591.1630246458748.27; _lxsdk_cuid=17b1a82a29fc8-0673099302ea63-4343363-1fa400-17b1a82a29fc8; uuid_n_v=v1; uuid=AF1C0F50F6B411EB9366DDA2ECF8019F87CC06A5AC564AC496C05F193B333A62; _lxsdk=AF1C0F50F6B411EB9366DDA2ECF8019F87CC06A5AC564AC496C05F193B333A62; Hm_lvt_703e94591e87be68cc8da0da7cbd0be2=1628254145,1628841166,1630221202,1630240621; __mta=244242106.1628254145571.1630240621474.1630240727899.15; Hm_lpvt_703e94591e87be68cc8da0da7cbd0be2=1630246458; _lxsdk_s=17b92149e10-b3e-df4-e9d%7C%7C23"
}

pro = {
    'http': 'http://112.104.28.117:3128'
}

import requests


def index():
    res = requests.get(url, headers = headers, proxies = pro)
    res.encoding = 'utf-8'
    with open('xl.html', 'wb') as f:
        f.write(res.content)
    return res


def get_font():
    html = index().text
    print(html)
    #  url('//vfile.meituan.net/colorstone/1bf855a5c988f1b58b2e69053366eccf2284.woff') format('woff');
    font_url = re.search(r"url\('(.*\.woff)'\)", html).group(1)
    res = requests.get('http:' + font_url)
    f = open('ff.woff', 'wb')
    f.write(res.content)


# get_font()

'''
from fontTools.ttLib import TTFont
xl = TTFont('ff.woff')
print(xl.getGlyphOrder())  # 读取字体编号  源文件  xml格式得
xl.saveXML('ff.xml')
'''

# 对比2个文件  9 e436   &#xe436   9 f4a0 &#xf4a0
'''
找模板定位 数字

相似度很高就认定这个数是对的

欧式距离计算 

'''
# 提取坐标
'''
nui = xl.getGlyphOrder()[2:]
axix = []
for u in nui:
    a = []
    for i in xl['glyf'][u].coordinates:
        a.append(i)
    axix.append(a)
print(axix)
'''

import fffffff

import requests

res = requests.get(url, headers = headers, proxies = pro)
res.encoding = 'utf-8'
res = res.text
print('*' * 50)
font_dict = fffffff.getFont(res)

# {'&#xf792;': '2', '&#xf887;': '8', '&#xe1ff;': '4', '&#xf4a3;': '6', '&#xe3ff;': '5', '&#xeba5;': '3', '&#xf732;': '1', '&#xec87;': '0', '&#xe9a5;': '9', '&#xe057;': '7'}

for key in font_dict.keys():
    res = res.replace(key, font_dict[key])
print(res)

with open('sss.html', 'w', encoding = 'utf-8') as f:
    f.write(res)

'''
第一步 找一个模板  字体转码包  先找对应关系


第二步
    找规律  ID会变   坐标变化不大  'uniE436':'9',

    找新的字体文件  坐标 对比 老的文件坐标

    然后再映射





'''